package router.interf;

import java.net.InetAddress;
import java.net.NetworkInterface;
import java.util.Timer;
import java.util.TimerTask;

import statemachine.StateInterface;

import events.EventManager;
import events.SendHelloEvent;
import events.WaitTimerExpiredEvent;


public class Interface {
	

	
	private ProtocolPacketReceiver receiver;
	private ProtocolPacketSender sender;
	
	public enum NetworkTypes{
		broadcast, pointToPoint, nbma, pointToMultiPoint, virtualLink;
	}
	
	private InetAddress ipAddress;
	private StateInterface state;
	private int areaID;
	private NetworkTypes networkType;
	private int cost;
	private int routerDeadIntervall; 
	private Timer helloTimer; 
	private Timer waitTimer;
	private int helloInterval;
	private NetworkInterface hardwareInterface;
	
	private class HelloTimerTask extends TimerTask{

		private Interface interf;
		
		public HelloTimerTask(Interface interf){
			this.interf = interf;
		}
		
		@Override
		public void run() {
			EventManager.getInstance().notifyTimerExpired(new SendHelloEvent(interf));
			
		}
		
	}
	
	private class WaitTimerTask extends HelloTimerTask{
		public WaitTimerTask(Interface interf) {
			super(interf);
		}
		
		@Override
		public void run(){
			EventManager.getInstance().notifyTimerExpired(new WaitTimerExpiredEvent(super.interf));
		}
		
	}
	
	public StateInterface getState(){
		return this.state;
	}
	
	public Interface(int areaID, String type, int cost, NetworkInterface hardwareInterf){
		
		this.areaID = areaID;
		
		this.cost = cost;
		this.hardwareInterface = hardwareInterf;
		
		this.networkType = NetworkTypes.valueOf(NetworkTypes.class, type);
		
		this.waitTimer = new Timer();
		waitTimer.schedule(new WaitTimerTask(this), routerDeadIntervall*1000);
		this.helloTimer = new Timer();
		helloTimer.schedule(new HelloTimerTask(this), helloInterval*1000);
		
		
	}
	
	public NetworkTypes getNetworkType(){
		return this.networkType;
	}
	
	public void sendHelloPacket(){
		//TODO Method-Stub
	}
	
	public void sendDatabaseDescriptionPacket(){
		//TODO Method-Stub
	}
	
	public void sendLinkStateRequestPacket(){
		//TODO Method-Stub
	}
	
	public void sendLinkStateUpdatePacket(){
		//TODO Method-Stub
	}
	
	public void sendLinkStateAckPacket(){
		//TODO Method-Stub
	}
	
	
	
}
